﻿using System;
namespace Xtee.Riik.Ee.Xsd.Xtee {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kehtivus_vastus", Namespace="http://x-tee.riik.ee/xsd/xtee.xsd", Target=typeof(KehtivusVastus))]
    public class KehtivusVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKehtivusVastus clazz;
        
        public KehtivusVastusSerializer(IKehtivusVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kehtivus");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Kehtivus))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("nimetus");
            if (clazz.Nimetus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimetus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimetus");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "kehtivus")) {
                goto kehtivus;
            }
            else {
                if ((Reader.LocalName == "nimetus")) {
                    goto nimetus;
                }
                else {
                    return;
                }
            }
        kehtivus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kehtivus_vastus>kehtivus");
            }
            clazz.Kehtivus = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("kehtivus")).Value;
            goto START;
        nimetus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kehtivus_vastus>nimetus");
            }
            clazz.Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimetus")).Value;
            goto START;
        }
    }
}
